Skip to content

Scripts: Security enablement during west build #87669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Aasimshaik11
Copy link

Added changes to automate the signing of zephyr security using customtool during the west build process.

Copy link

Hello @Aasimshaik11, and thank you very much for your first pull request to the Zephyr project!
Our Continuous Integration pipeline will execute a series of checks on your Pull Request commit messages and code, and you are expected to address any failures by updating the PR. Please take a look at our commit message guidelines to find out how to format your commit messages, and at our contribution workflow to understand how to update your Pull Request. If you haven't already, please make sure to review the project's Contributor Expectations and update (by amending and force-pushing the commits) your pull request if necessary.
If you are stuck or need help please join us on Discord and ask your question there. Additionally, you can escalate the review when applicable. 😊

@Aasimshaik11 Aasimshaik11 force-pushed the zephyr-boot-security branch 2 times, most recently from 7541fb9 to 7052317 Compare March 26, 2025 11:28
@Aasimshaik11 Aasimshaik11 force-pushed the zephyr-boot-security branch from 7052317 to da52b68 Compare April 4, 2025 06:46
@jerome-pouiller jerome-pouiller self-requested a review April 4, 2025 09:55
CMakeLists.txt Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert these unrelated changes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved this comment

@@ -3,3 +3,25 @@

config BOARD_SIWX917_RB4338A
select SOC_PART_NUMBER_SIWG917M111MGTBA

# Kconfig.board for SiWx917 RB4338A
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary comment, please remove.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved this comment


# Kconfig.board for SiWx917 RB4338A

config SIGNING_ENABLED
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signing support should be a property of the SiWx91x SoC, not of the board. All of this must move to soc/silabs/silabs_siwx91x/, and the Kconfig options must be renamed to show that they apply to 91x only.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved this comment

@@ -11,3 +11,71 @@ include(${ZEPHYR_BASE}/boards/common/silabs_commander.board.cmake)
# Once started, it should be possible to reset the device with "monitor reset"
board_runner_args(jlink "--device=Si917" "--speed=10000")
include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake)

# Custom signing with Silicon Labs Commander
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to SoC level

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved this comment


# Define paths and keys from Kconfig
set(WORKSPACE_ROOT $ENV{PWD})
set(SL_COMMANDER_PATH $ENV{PWD}/SimplicityCommander-Linux/commander/commander)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't hardcode the path to Commander. You must assume that it exists on PATH.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I resolved this

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved this comment

@@ -79,6 +80,21 @@
[rimage] sections in your west config file(s); this is especially useful
when invoking west sign _indirectly_ through CMake/ninja. See how at
https://docs.zephyrproject.org/latest/develop/west/sign.html

sirps
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be silabs_rps or silabs_commander_rps for consistency with the silabs_commander runner.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved this comment


# Primary source: Board Kconfig defaults
board_dir = cache.get('BOARD_DIR') # Fallback to PWD if BOARD_DIR missing
board_kconfig = pathlib.Path(board_dir) / 'Kconfig.siwx917_r4338a'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't hard-code the board Kconfig path, this must generically work for all SiWx91x based boards.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved this comment

message(STATUS "Private key found at '${M4_PRIVATE_KEY}'")
endif()

# Define the commander signing command
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this calling Commander directly, and not invoking west sign?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The direct call to Silicon Labs Commander in board.cmake is intentional to integrate signing into the west build process, ensuring that zephyr.bin.rps is generated automatically as part of the build output for SiWx917-based boards. This approach is used to meet hardware requirements where a signed binary is mandatory for flashing or execution. Invoking west sign would require a separate post-build step, which we avoid here to streamline the workflow and guarantee that the signed artifact is available immediately after west build, consistent with the board’s firmware deployment needs.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would a post-build step need to be separately invoked just because it's calling west instead of Commander? There is no difference if west sign or commander is called as a custom command.

Copy link
Author

@Aasimshaik11 Aasimshaik11 Apr 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's right. We can do that too, But there will be extra call of west sign that's it.

If west sign used:
Cmakefile -> west sign -> sign.py -> commander for signing

If not west sign:
Cmake -> Commander

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it would be better to call west sign, in order to avoid duplicating the implementation. The overhead of an extra call is well worth avoiding two implementations of the same logic.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved this comments

@Aasimshaik11 Aasimshaik11 force-pushed the zephyr-boot-security branch 4 times, most recently from 726af6b to b9ddd52 Compare April 8, 2025 10:31
@Aasimshaik11 Aasimshaik11 marked this pull request as ready for review April 9, 2025 04:34
@github-actions github-actions bot added platform: Silabs Silicon Labs area: West West utility labels Apr 9, 2025
pdgendt
pdgendt previously requested changes Apr 9, 2025
@Aasimshaik11 Aasimshaik11 force-pushed the zephyr-boot-security branch 2 times, most recently from 6015f25 to d329322 Compare April 9, 2025 09:35
@pdgendt
Copy link
Collaborator

pdgendt commented Apr 9, 2025

Please, do not resolve comments as per the contribution guidelines.

@Aasimshaik11 Aasimshaik11 force-pushed the zephyr-boot-security branch 2 times, most recently from 82ac254 to 2a2c05b Compare April 9, 2025 11:29
default "Give_full_path_to_SimplicityCommander-Linux/commander/commander"
depends on SILABS_COMMANDER_SIGN
help
Path to the Silicon Labs Commander executable, relative to the current working directory (e.g., $ENV{PWD}), used for signing the firmware binary.
Copy link
Collaborator

@jerome-pouiller jerome-pouiller Apr 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kconfig files are indented with one tab. The help message is indented with one tab + 2 spaces.

The help text word-warped at 80 columns.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved this comment

@@ -633,3 +648,144 @@ def sign(self, command, build_dir, build_conf, formats):

os.remove(out_bin)
os.rename(out_tmp, out_bin)

class Silabs_rpsSigner(Signer):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silabs_rpsSigner?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SilabsRPSSigner is this fine?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved this comment

elif current_config == 'M4_PRIVATE_KEY':
m4_private_key = value
elif current_config == 'COMMANDER_PATH':
commander_path = value
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6 level of indentation is a lot, especially in a function of 125 lines. Probably you could introduce a subfunction.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved this comment

workspace_base = pathlib.Path(os.getcwd())
if not args.quiet:
command.inf(f"ZEPHYR_WORKSPACE_ROOT not set, using current directory: {workspace_base}")
soc_dir = 'GIVE PATH FOR KCONFIG.SOC AFTER WORKSPACE' # Same relative path
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it temporary code?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved this comment

if(CONFIG_SILABS_COMMANDER_SIGN)

# Define input and output files
set(ZEPHYR_BINARY ${CMAKE_BINARY_DIR}/zephyr/zephyr.bin)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WHat is the difference with ${KERNEL_BIN_NAME}?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It takes the Kernel name which is already defined.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, let the reviewer resolve the comments. I think this is a valid point, instead of hard-coding the path, use the existing CMake variable.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved this comment

COMMENT "Ensuring signing with Silicon Labs Commander is complete"
)
else()
message(STATUS "CONFIG_SIGNING_ENABLED is not enabled")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we have to manage the non-signed binaries.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If signed_binary is needed for the user it do's that by checking the variable CONFIG_SIGNING_ENABLED.
If not it goes through with the default one.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved this comment

set(SIGNED_RPS ${CMAKE_BINARY_DIR}/zephyr/zephyr.bin.rps)

# Use $ENV{PWD} as working directory
set(WORKSPACE_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of creating a variable with the exact same value of an existing variable?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved this comment

set(WORKSPACE_ROOT ${CMAKE_CURRENT_SOURCE_DIR})

# Define the west sign command with explicit working directory and environment
set(west_sign_cmd
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the variables are uppercase in CMakeLists.txt

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved this comment


# Define input and output files
set(ZEPHYR_BINARY ${CMAKE_BINARY_DIR}/zephyr/zephyr.bin)
set(SIGNED_RPS ${CMAKE_BINARY_DIR}/zephyr/zephyr.bin.rps)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be consistent in the variable names.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved this comment

${WEST} sign
-t silabs_rps
-d ${CMAKE_BINARY_DIR}
--sbin ${SIGNED_RPS}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have to handle `CONFIG_FLASH_LOAD_OFFSET``

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved this comment

@Aasimshaik11 Aasimshaik11 force-pushed the zephyr-boot-security branch 3 times, most recently from 46bdfdf to c6cbbf6 Compare April 18, 2025 06:20
Copy link
Collaborator

@jerome-pouiller jerome-pouiller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you split your commit in two parts:

  • Add support for west sign -r silabs_commander
  • Add support for west build -t signed-rps

@@ -112,7 +125,7 @@ def do_add_parser(self, parser_adder):

# general options
group = parser.add_argument_group('tool control options')
group.add_argument('-t', '--tool', choices=['imgtool', 'rimage'],
group.add_argument('-t', '--tool', choices=['imgtool', 'rimage', 'silabs_rps'],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of the binary the user install is commander. This tool is referenced with silabs_commander in Zephyr. I suggest to not introduce a new naming scheme.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved this comment

@@ -633,3 +648,147 @@ def sign(self, command, build_dir, build_conf, formats):

os.remove(out_bin)
os.rename(out_tmp, out_bin)

class SilabsRPSSigner(Signer):
"""Signer class for Silicon Labs Commander tool via west sign -t silabs_rps."""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file tends to use usual comments (starting with #) rather than docstring. Let's be consistent.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved this comment

commander_path = value
else:
if not args.quiet:
command.inf(f"No Kconfig.defconfig found at {soc_kconfig}. Using default values.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you retrieve the values from build_conf?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved this comment

if not m4_private_key:
command.die("M4_PRIVATE_KEY not set in Kconfig.defconfig and no --m4-private-key provided.")
if not commander_path:
command.die("COMMANDER_PATH not set in Kconfig.defconfig and no --commander-path provided.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_security_config() never return unset values. So, can any of these condition happen?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved this comment

if not m4_private_key:
command.die("M4_PRIVATE_KEY not set in Kconfig.defconfig and no --m4-private-key provided.")
if not commander_path:
command.die("COMMANDER_PATH not set in Kconfig.defconfig and no --commander-path provided.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, why do you enforce the user to provide the name of the commander command. It is very likely commander.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved this comment

default "Full_path_to_m4_private_key.pem"

config COMMANDER_PATH
default "Full_path_to_SimplicityCommander-Linux/commander/commander"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, the usual user will have commander in hs PATH.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved this comment

default "Full_OTA_KEY_in_HEX"

config M4_PRIVATE_KEY
default "Full_path_to_m4_private_key.pem"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you provide default values if they are not correct?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified the code

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved this comment

@@ -13,6 +13,21 @@ configdefault SYS_CLOCK_TICKS_PER_SEC
default 128 if !TICKLESS_KERNEL && SILABS_SLEEPTIMER_TIMER
default 1024 if SILABS_SLEEPTIMER_TIMER

config SILABS_COMMANDER_SIGN
default n
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

n is already the default.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

parser = subparsers.add_parser('silabs_rps', help='Sign with Silicon Labs Commander')
parser.add_argument('--m4-ota-key', help='OTA key for signing (overrides Kconfig.defconfig default)')
parser.add_argument('--m4-private-key', help='Absolute path to private key file (overrides Kconfig.defconfig default)')
parser.add_argument('--commander-path', help='Absolute path to Commander executable (overrides Kconfig.defconfig default)')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These option should override CONFIG_M4_OTA_KEY, CONFIG_M4_PRIVATE_KEY and CONFIG_COMMANDER_PATH.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved

)

# Add custom target to ensure signing is part of the build
add_custom_target(silabs_rps_sign_target
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the user facing name. Don't we have a better name? signed-rps?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, what is the purpose of this target? The user can already run west sign. Why do we provide west build -t silabs_rps_sign_target?

It would be more useful if the signing process was included in the default build.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, let the reviewer resolve the comments.

It would be more useful if the signing process was included in the default build.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

@Aasimshaik11 Aasimshaik11 force-pushed the zephyr-boot-security branch from c6cbbf6 to f9c082c Compare April 20, 2025 08:14
@github-actions github-actions bot added the area: Samples Samples label Apr 20, 2025
@github-actions github-actions bot requested review from kartben and nashif April 20, 2025 08:14
@Aasimshaik11 Aasimshaik11 force-pushed the zephyr-boot-security branch 3 times, most recently from 2ac309f to 009ada8 Compare April 21, 2025 05:42
west sign -t silabs_commander -- --mic YOUR_OTA_KEY --encrypt YOUR_OTA_KEY --sign YOUR_PRIVATE_KEY.pem
or west sign -t silabs_commander

For this to work, SILABS Commander tool must be installed in your PATH.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silicon Labs (or possibly Silabs)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

if line.strip().startswith('CONFIG_M4_OTA_KEY='):
m4_ota_key = line.split('=')[1].strip().strip('"')
elif line.strip().startswith('CONFIG_M4_PRIVATE_KEY='):
m4_private_key = line.split('=')[1].strip().strip('"')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need this at all? Can't you use:

    build_conf.get('CONFIG_M4_OTA_KEY')
    build_conf.get('CONFIG_M4_PRIVATE_KEY')

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need , I added the fallback initially to cover potential retrieval issues. Now using .get() will resolve them.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

for path in default_paths:
if os.path.isfile(path):
commander_path = path
break
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KISS.

The system already manage that for you. (/usr/bin and /usr/bin/local are already part of the default PATH. If they are not, it is not your job to fix it).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

if not m4_private_key:
command.die("M4_PRIVATE_KEY not provided via --m4-private-key or set in prj.conf. Please specify --m4-private-key=/path/to/key or add CONFIG_M4_PRIVATE_KEY in prj.conf.")
if not commander_path:
command.die("Commander not found automatically. Please provide --commander-path=/path/to/commander or install it in your PATH.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

west sign already has the --tool-path option. Please use it:

def find_commandertool(cmd, args):
    if args.tool_path:
        commandertool = args.tool_path
        if not os.path.isfile(commandertool):
            cmd.die(f'--tool-path {commandertool}: no such file')
    else:
        commandertool = shutil.which('commander')
        if not commandertool:
            cmd.die('commander not found')
 return commandertool

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not able to find find_commandertool in sign.py.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant, you can write a such function.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

command.die("ZEPHYR_BASE environment variable not set. Ensure you are running within a Zephyr build environment.")
workspace_base = pathlib.Path(zephyr_base)
if not workspace_base.is_dir():
command.die(f"Invalid ZEPHYR_BASE directory: {workspace_base}. Please check your Zephyr setup.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not a specialist of the west commands, but I believe you should use zephyr_ext_common to retrieve ZEPHYR_BASE.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

kernel_name = build_conf.get('CONFIG_KERNEL_BIN_NAME', 'zephyr')

# Input and output files (using BUILD_DIR)
in_bin = b / 'zephyr' / f"{kernel_name}.bin.rps" # Raw binary input
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name in_bin, the comment Raw binary input and the error messages No unsigned .bin found are confusing.
In fact, the input is not a binary file. It is a .rps file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

add_subdirectory(siwg917)
zephyr_include_directories(.)
zephyr_sources_ifdef(CONFIG_SOC_SERIES_SIWG917 soc.c)
zephyr_sources_ifdef(CONFIG_WISECONNECT_NETWORK_STACK nwp_init.c)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant with soc/silabs/silabs_siwx91x/siwg917/CMakeLists.txt. BTW, nwp_init.c has been replaced by nwp.c a few weeks ago.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved


# Custom signing with Silicon Labs Commander
if(CONFIG_SiWX91X_SILABS_COMMANDER_SIGN)
# Define input and output files
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which input files? Outdated comments are worse than no comments.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

# Custom signing with Silicon Labs Commander
if(CONFIG_SiWX91X_SILABS_COMMANDER_SIGN)
# Define input and output files
set(SIGNED_RPS ${PROJECT_BINARY_DIR}/zephyr/${KERNEL_BIN_NAME}.bin.rps)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need absolute path? I believe you need it only because you change WORKING_DIRECTORY below. You can probably remove remove all this complexity.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

)

# Add custom target to ensure signing is part of the build
add_custom_target(silabs_rps_sign_target
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, let the reviewer resolve the comments.

It would be more useful if the signing process was included in the default build.

@Aasimshaik11 Aasimshaik11 force-pushed the zephyr-boot-security branch 3 times, most recently from 964683e to 82595cd Compare April 25, 2025 05:16
@@ -23,6 +22,7 @@
from runners.core import BuildConfiguration
from zcmake import CMakeCache
from zephyr_ext_common import Forceable, ZEPHYR_SCRIPTS
from zephyr_ext_common import ZEPHYR_BASE
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import can be added to the above line instead of adding a new one.

help
Activates the signing process for the Zephyr binary using Silicon Labs Commander during the build process.

config M4_OTA_KEY
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These options should be SIWX91X_OTA_KEY and SIWX91X_PRIVATE_KEY in my opinion, in order to be properly namespaced.


# Resolve paths
tool_path = pathlib.Path(commander_path)
if not tool_path.is_file():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check seems to duplicate what's already been done in find_commandertool, so it should never happen. Consider making use of this detailed error message in the earlier check and removing it from here.

add_subdirectory(siwg917)
zephyr_include_directories(.)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of changing the include path of the CMake build? This seems unrelated to signing support.

@Aasimshaik11 Aasimshaik11 force-pushed the zephyr-boot-security branch from 82595cd to 7107751 Compare April 30, 2025 10:52
Copy link
Author

@Aasimshaik11 Aasimshaik11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have resolved all the comments from @asmellby , @jerome-pouiller , @jhedberg , and @pdgendt . Could you mark these comments as resolved and provide any further suggestions or approval for my PR?

Added changes to automate the signing of zephyr security
using customtool during the west build process.

Signed-off-by: Aasim Shaik <[email protected]>
@Aasimshaik11 Aasimshaik11 force-pushed the zephyr-boot-security branch from 7107751 to 69b832a Compare May 5, 2025 08:03
@pdgendt pdgendt dismissed their stale review May 5, 2025 09:28

Resolved request changes

@pdgendt pdgendt assigned jhedberg and asmellby and unassigned pdgendt May 5, 2025
@pdgendt
Copy link
Collaborator

pdgendt commented May 5, 2025

Re-assigned to Silabs maintainers.

@@ -12,3 +14,31 @@ set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
${KERNEL_BIN_NAME}
${KERNEL_BIN_NAME}.rps
)

# Custom signing with Silicon Labs Commander
if(CONFIG_SiWX91X_SILABS_COMMANDER_SIGN)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: SiWX91X -> SIWX91X (lowercase i)


# Set the flash file based on signing is enabled or not.
set(FLASH_FILE ${PROJECT_BINARY_DIR}/zephyr_signed.bin.rps)
if(NOT EXISTS ${FLASH_FILE})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you think we should rather test CONFIG_SIWX91X_SILABS_COMMANDER_SIGN ?

# Set the flash file based on signing is enabled or not.
set(FLASH_FILE ${PROJECT_BINARY_DIR}/zephyr_signed.bin.rps)
if(NOT EXISTS ${FLASH_FILE})
set(FLASH_FILE ${PROJECT_BINARY_DIR}/zephyr.bin.rps)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Later in the script we refer to ${KERNEL_BIN_NAME}.rps or to ${CONFIG_KERNEL_BIN_NAME}_signed.bin.rps


To create a signed binary with the silabs_commander tool, run this from your build directory:

west sign -t silabs_commander -- --mic YOUR_OTA_KEY --encrypt YOUR_OTA_KEY --sign YOUR_PRIVATE_KEY.pem
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this does not match with get_security_configs().

"--app", str(input_rps),
"--mic", siwx91x_ota_key,
"--encrypt", siwx91x_private_key,
"--sign", str(private_key_path)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain the difference between siwx91x_private_key and str(private_key_path)?


private_key_path = pathlib.Path(siwx91x_private_key)
if not private_key_path.is_file():
command.die(f"Private key not found at {private_key_path}. Please ensure the path is correct.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to group this check with the other related ones in get_security_configs().

# Define the west sign command with explicit working directory and environment
set(WEST_SIGN_CMD
${CMAKE_COMMAND} -E chdir ${CMAKE_BINARY_DIR} # Explicitly set working directory
${CMAKE_COMMAND} -E env "PATH=$ENV{PATH}:$ENV{WEST_ROOT}/bin" "ZEPHYR_WORKSPACE_ROOT=${CMAKE_CURRENT_SOURCE_DIR}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe my previous comment is still relevant.

ALL
DEPENDS ${KERNEL_BIN_NAME}.rps
COMMENT "Ensuring signing with Silicon Labs Commander is complete"
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this target is useless (the user can run west sign). However, you can add some entries to extra_post_build_commands to launch the signature automatically with west build.

# Add custom command to invoke west sign during build
add_custom_command(
OUTPUT ${KERNEL_BIN_NAME}.rps
COMMAND ${CMAKE_COMMAND} -E echo "Forcing execution in ${PROJECT_BINARY_DIR}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this trace relevant? I believe it bring any useful information to the user.

config SIWX91X_PRIVATE_KEY
string "Private Key Path for Signing (sourced from prj.conf)"
help
Path to private key file for signing with Silicon Labs Commander, from prj.conf, relative to board directory.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These options should not be displayed to the user if SOC_FAMILY_SILABS_SIWX91X is not selected. You need to if SOC_FAMILY_SILABS_SIWX91X.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Samples Samples area: West West utility platform: Silabs Silicon Labs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants